﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Rtgs.master" AutoEventWireup="true"
    CodeFile="stp_userlist.aspx.cs" Inherits="page_rtgs_stp_userlist" %>

<%@ Register Src="~/usercontrol/searching.ascx" TagPrefix="uc" TagName="searching" %>
<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveClientUrl("~/css/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveClientUrl("~/script/i18n/grid.locale-en.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveClientUrl("~/script/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveClientUrl("~/script/helper.js") %>" type="text/javascript"></script>
     <script type="text/javascript" src="<%= ResolveClientUrl("~/script/jquery.fmatter.js") %>"></script>
    <div>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Add"
            onclick="OpenForm('add')"><span class="ui-icon ui-icon-plus"></span>Add</a>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Edit"
            onclick="OpenForm('edit');"><span class="ui-icon ui-icon-pencil"></span>Edit</a>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Delete"
            onclick="OpenForm('delete');"><span class="ui-icon ui-icon-trash"></span>Delete</a>
    </div>
    <br />
    <uc:searching ID="ucSearch" ClassName="stpUser" IncludeParameter="=,like" AliasField="username=User Name"
        runat="server" />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveClientUrl("~/ajaxhandler/rtgs/stp_user.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['User Name', 'Password', 'User Create Time', 'User Update Time', 'User Group', 'User Max Amount'],
            colModel: [
           		{ name: 'username', index: 'USERNAME', width: 200 },
           		{ name: 'userhash', index: 'USERHASH', width: 200 },
                { name: 'usercreateTime', index: 'USERCREATE_TIME', width: 200, sorttype: 'date', formatter: 'date', formatoptions: { newformat: 'd M Y h:m:s'} },
                //{ name: 'expiredDate', index: 'EXPIRED_DATE', width: 150, sorttype: 'date', formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                {name: 'userupdateTime', index: 'USERUPDATE_TIME', width: 200, sorttype: 'date', formatter: 'date', formatoptions: { newformat: 'd M Y h:m:s'} },
                { name: 'groups', index: 'groups', width: 200 },
                { name: 'usermaxAmount', index: 'USERMAX_AMOUNT', width: 200 }

           		           	],
            rowNum: 10,
            id: 'USERNAME',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'USERNAME',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 'auto',
            height: '100%',
            caption: 'User',
            ajaxGridOptions: { cache: false },
            ondblClickRow: function () {
                OpenForm('edit');
            }
        });

        function OpenForm(ctl) {

            var grid = $("#table");
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'username'));
            });

            //alert(selText);

            if (ctl == "edit") {
                $("#dialog").load('../../form/rtgs/stp_userform.aspx?id=' + encodeURIComponent(selText)).dialog({ autoOpen: false, modal: true, width: 500, title: 'Edit Data' });
                $("#dialog").dialog('open');
            }
            else if (ctl == "add") {
                $("#dialog").load('../../form/rtgs/stp_userform.aspx').dialog({ autoOpen: false, modal: true, width: 500, title: 'Add Data' });
                $("#dialog").dialog('open');
            }
            else {
                var result = window.confirm('Are you sure that you want to delete?');
                if (result) {
                    CallAjax("../../ajaxhandler/rtgs/stp_user.ashx", "?method=delete" + "&id=" + encodeURIComponent(selText));

                    setTimeout("$('#table').trigger('reloadGrid');", 3000);
                }
            }
        }
    
    </script>
    <script type="text/javascript">

        $('#btnSearch').click(function () {
            var field = $('#<%= ucSearch.ClientID %>_ddlField').val();
            var operand = $('#<%= ucSearch.ClientID %>_ddlOperand').val();
            var value = $('#<%= ucSearch.ClientID %>_txtValue').val();

            var handlerUrl = '<%= ResolveClientUrl("~/ajaxhandler/rtgs/stp_user.ashx") %>';

            $('#table').jqGrid('setGridParam', {
                url: handlerUrl + '?method=getdata' + '&field=' + field + '&operand=' + operand + '&value=' + value
            }).trigger('reloadGrid', [{ page: 1}]);
            return false;
        });
    
    </script>
</asp:Content>
